/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Heinz Hernandez
 */
@Entity
@Table(name = "pet")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Pet.findByPetNameLike", query = "SELECT p FROM Pet p WHERE lower(p.petName) like :petName"),
    @NamedQuery(name = "Pet.findByPerId", query = "SELECT p FROM Pet p WHERE p.perId = :perId"),
    @NamedQuery(name = "Pet.findByPerIdOwn", query = "SELECT p FROM Pet p WHERE p.perIdown = :perIdown"),
    @NamedQuery(name = "Pet.findAll", query = "SELECT p FROM Pet p"),
    @NamedQuery(name = "Pet.findByPetId", query = "SELECT p FROM Pet p WHERE p.petId = :petId"),
    @NamedQuery(name = "Pet.findByPetName", query = "SELECT p FROM Pet p WHERE p.petName = :petName"),
    @NamedQuery(name = "Pet.findByPetSpecies", query = "SELECT p FROM Pet p WHERE p.petSpecies = :petSpecies"),
    @NamedQuery(name = "Pet.findByPetAge", query = "SELECT p FROM Pet p WHERE p.petAge = :petAge"),
    @NamedQuery(name = "Pet.findByPetWeight", query = "SELECT p FROM Pet p WHERE p.petWeight = :petWeight")})
public class Pet implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "PET_ID")
    private Long petId;
    @Basic(optional = false)
    @Column(name = "PET_NAME")
    private String petName;
    @Basic(optional = false)
    @Column(name = "PET_SPECIES")
    private String petSpecies;
    @Basic(optional = false)
    @Column(name = "PET_AGE")
    private int petAge;
    @Basic(optional = false)
    @Column(name = "PET_WEIGHT")
    private float petWeight;
    @Basic(optional = false)
    @Lob
    @Column(name = "PET_IMG")
    private byte[] petImg;
    @OneToMany(mappedBy = "petId")
    private List<Record> recordList;
    @JoinColumn(name = "PER_IDOWN", referencedColumnName = "PER_ID")
    @ManyToOne
    private Person perIdown;
    @JoinColumn(name = "PER_ID", referencedColumnName = "PER_ID")
    @ManyToOne
    private Person perId;

    public Pet() {
    }

    public Pet(Long petId) {
        this.petId = petId;
    }

    public Pet(Long petId, String petName, String petSpecies, int petAge, float petWeight, byte[] petImg) {
        this.petId = petId;
        this.petName = petName;
        this.petSpecies = petSpecies;
        this.petAge = petAge;
        this.petWeight = petWeight;
        this.petImg = petImg;
    }

    public Long getPetId() {
        return petId;
    }

    public void setPetId(Long petId) {
        this.petId = petId;
    }

    public String getPetName() {
        return petName;
    }

    public void setPetName(String petName) {
        this.petName = petName;
    }

    public String getPetSpecies() {
        return petSpecies;
    }

    public void setPetSpecies(String petSpecies) {
        this.petSpecies = petSpecies;
    }

    public int getPetAge() {
        return petAge;
    }

    public void setPetAge(int petAge) {
        this.petAge = petAge;
    }

    public float getPetWeight() {
        return petWeight;
    }

    public void setPetWeight(float petWeight) {
        this.petWeight = petWeight;
    }

    public byte[] getPetImg() {
        return petImg;
    }

    public void setPetImg(byte[] petImg) {
        this.petImg = petImg;
    }

    @XmlTransient
    public List<Record> getRecordList() {
        return recordList;
    }

    public void setRecordList(List<Record> recordList) {
        this.recordList = recordList;
    }

    public Person getPerIdown() {
        return perIdown;
    }

    public void setPerIdown(Person perIdown) {
        this.perIdown = perIdown;
    }

    public Person getPerId() {
        return perId;
    }

    public void setPerId(Person perId) {
        this.perId = perId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (petId != null ? petId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pet)) {
            return false;
        }
        Pet other = (Pet) object;
        if ((this.petId == null && other.petId != null) || (this.petId != null && !this.petId.equals(other.petId))) {
            return false;
        }
        return true;
    }

    @Override
//    public String toString() {
//        return "Entities.Pet[ petId=" + petId + " ]";
//    }
    public String toString() {
        return "ID:  " + petId + "  NAME: " + petName;
    }
}
